import axios from 'axios';
//调用接口应该卸载service，此处为了演示
function getGoods() {
  return axios.get('/api/goods');
}
export default {
  namespace: 'goods', //model的命名空间，区分多个model
  state: [], //初始状态
  effects: {
    *getList(action, { call, put }) {
      const res = yield call(getGoods);
      yield put({ type: 'initGoods', payload: res.data.result });
    },
  }, //异步操作saga
  reducers: {
    initGoods(state, action) {
      return action.payload;
    },
    addGood(state, action) {
      return [...state, { title: action.payload.title }];
    },
  }, //操作action
};
